package org.dalmatian.common.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 文件类型对应文件MIME类型枚举类
 */

@Getter
@AllArgsConstructor
public enum FileContentTypeEnum {

    // 常见文件类型
    WORD_DOC("0", "doc", "application/msword", ".doc"),
    WORD_DOCX("1", "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".docx"),
    EXCEL_XLS("2", "xls", "application/vnd.ms-excel", ".xls"),
    EXCEL_XLSX("3", "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".xlsx"),
    POWERPOINT_PPT("4", "ppt", "application/vnd.ms-powerpoint", ".ppt"),
    POWERPOINT_PPTX("5", "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".pptx"),
    PDF("6", "pdf", "application/pdf", ".pdf"),
    TEXT("7", "txt", "text/plain", ".txt"),
    RTF("8", "rtf", "application/rtf", ".rtf"),
    HTML("9", "html", "text/html", ".html"),
    CSV("10", "csv", "text/csv", ".csv"),
    ZIP("11", "zip", "application/zip", ".zip"),
    RAR("12", "rar", "application/x-rar-compressed", ".rar"),
    IMAGE_JPEG("13", "jpeg", "image/jpeg", ".jpeg"),
    IMAGE_JPG("14", "jpg", "image/jpeg", ".jpg"),
    IMAGE_PNG("15", "png", "image/png", ".png"),
    IMAGE_GIF("16", "gif", "image/gif", ".gif"),
    AUDIO_MPEG("17", "mp3", "audio/mpeg", ".mp3"),
    AUDIO_WAV("18", "wav", "audio/wav", ".wav"),
    VIDEO_MP4("19", "mp4", "video/mp4", ".mp4"),
    VIDEO_MKV("20", "mkv", "video/x-matroska", ".mkv"),
    VIDEO_AVI("28", "avi", "video/x-msvideo", ".avi"),
    VIDEO_FLV("29", "flv", "video/x-flv", ".flv"),
    VIDEO_MOV("30", "mov", "video/quicktime", ".mov"),
    // 此处类别名 VIDEO_WAV 但 MIME 类型和扩展名属于音频，建议确认是否更改
    VIDEO_WAV("31", "wav", "audio/wav", ".wav"),
    VIDEO_WEBM("32", "webm", "video/webm", ".webm"),
    XML("21", "xml", "application/xml", ".xml"),
    JSON("22", "json", "application/json", ".json"),
    SVG("23", "svg", "image/svg+xml", ".svg"),
    TAR("24", "tar", "application/x-tar", ".tar"),
    GZIP("25", "gz", "application/gzip", ".gz"),
    EPUB("26", "epub", "application/epub+zip", ".epub"),
    ICO("27", "ico", "image/x-icon", ".ico");


    private final String code;
    private final String name;
    private final String value;
    private final String suffix;

    public static String getValueByName(String name) {
        for (FileContentTypeEnum type : values()) {
            if (type.getName().equalsIgnoreCase(name)) {
                return type.getValue();
            }
        }
        throw new IllegalArgumentException("Unknown file name: " + name);
    }

    public static String getValueByCode(String code) {
        for (FileContentTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type.getValue();
            }
        }
        throw new IllegalArgumentException("Unknown file code: " + code);
    }

    public static String getNameByCode(String code) {
        for (FileContentTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type.getName();
            }
        }
        throw new IllegalArgumentException("Unknown file code: " + code);
    }

    // 新增简化文件类型映射方法
    public static String simplifyFileType(String originalType) {
        switch (originalType.toLowerCase()) {
            case "docx":
                return "doc";
            case "xlsx":
                return "xls";
            case "pptx":
                return "ppt";
            case "jpeg":
            case "png":
                return "jpg";
            default:
                return originalType; // 默认返回原始类型
        }
    }
}
